// 获取短信类型Name
const getSMSType = (str) => {
  switch (str) {
    case 'ALI_CLOUD':
      return window.I18n.ALI_CLOUD
    case 'MEKONG':
      return window.I18n.MEKONG
    default:
      return ''
  }
}

// 根据base64转成文件下载地址, base64: 编码, type转换的类型
const loadUrl = (base64, type) => {
  var sliceSize = 512;
  var byteCharacters = atob(base64);
  var byteArrays = [];
  for (var offset = 0; offset < byteCharacters.length; offset += 512) {
    var slice = byteCharacters.slice(offset, offset + sliceSize);

    var byteNumbers = new Array(slice.length);
    for (var i = 0; i < slice.length; i++) {
      byteNumbers[i] = slice.charCodeAt(i);
    }

    var byteArray = new Uint8Array(byteNumbers);

    byteArrays.push(byteArray);
  }

  var blob = new Blob(byteArrays, { type: `application/${type}` });
  return URL.createObjectURL(blob)
}

const loadBlob = (blob, name) => {
  var a = document.createElement('a')
  a.href = window.URL.createObjectURL(blob)
  a.download = name
  a.click()
}

// 比较两个对象数组是否相等
const equalArr = (arr1, arr2) => {
  let flag = true
  arr1.forEach((v, i) => {
    /* eslint-disable */
    if (JSON.stringify(v) != JSON.stringify(arr2[i])) {
      flag = false
    }
  })
  return flag
}

export {
  getSMSType,
  loadUrl,
  equalArr,
  loadBlob
}
